//
//  HMWelcomeViewController.swift
//  CZBKWB31
//
//  Created by Linkon Y on 16/8/11.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class HMWelcomeViewController: UIViewController {

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        headImageView.snp_updateConstraints { (make) in
            make.top.equalTo(view).offset(100)
            
        }
        //设置动画
        /**
         
         
         - parameter <Tduration:             动画时长
         - parameter delay:                  延迟
         - parameter usingSpringWithDamping: 阻尼系数
         - parameter initialSpringVelocity:  起始速度
         - parameter options:                动画方式
   
         */
        UIView.animateWithDuration(2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { 
            //纯代码（使用约束）动画要用此方法 （强制刷新UI）
            self.view.layoutIfNeeded()
          
            
            }) { (_) in
                UIView.animateWithDuration(0.25, animations: { 
                    self.messageLab.alpha = 1
                    }, completion: { (_) in
                        //发送通知，告知切换根控制器
                        NSNotificationCenter.defaultCenter().postNotificationName(WBSWITCHROOTVCNOTIFICATION, object: nil)
                })
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
       setupUI()

    }
     // MARK: - 设置视图
    func setupUI(){
    //增加控件
        view.addSubview(bgImageView)
        view.addSubview(headImageView)
        view.addSubview(messageLab)
    //增加约束
        bgImageView.snp_makeConstraints { (make) in
            //edgeb边缘
            make.edges.equalTo(view).offset(UIEdgeInsetsZero)
        }
        headImageView.snp_makeConstraints { (make) in
            make.width.height.equalTo(CGSize(width: 90,height: 90))
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)
            
        }
        messageLab.snp_makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(headImageView.snp_bottom).offset(16)
            
        }
        
    
    }
    // MARK: - 增加控件
    //背景图片
    private lazy var bgImageView: UIImageView = UIImageView(imageName:"ad_background")
    //头像
    private lazy var headImageView: UIImageView = {
    
        let image = UIImageView(imageName: "avatar_default_big")
        
//        image.sd_setImageWithURL(NSURL(string:HMUserAccountViewModel.sharedTools.userAccount?.avatar_large ?? ""), placeholderImage: UIImage(named:"avatar_default_big"))
        //使用自己封装的方法
        image.hm_setImageWithString(HMUserAccountViewModel.sharedTools.userAccount?.avatar_large, placeholderImageName: "avatar_default_big")
        //切圆
        image.layer.cornerRadius = 45
        image.layer.masksToBounds = true
        return image
    }()
    //欢迎回来
    private lazy var messageLab:UILabel = {
        let lab = UILabel()
        lab.font = UIFont.systemFontOfSize(18)
        lab.text = "欢迎回来"
        lab.textColor = UIColor.darkGrayColor()
        lab.textAlignment = .Center
        lab.alpha = 0
        
        return lab
     }()
    
}
